package day10.download;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.UUID;

public class Upload implements Runnable {
    private Socket s;

    public Upload(Socket s) {
        this.s = s;
    }

    @Override
    public void run() {
        try (
                InputStream is = s.getInputStream();

                OutputStream os = new FileOutputStream("src\\main\\resources\\" + UUID.randomUUID().toString().substring(0, 8) + ".wma");
                OutputStream os2 = s.getOutputStream();
            ){
            int len = 0;
            byte[] b = new byte[1024];
            while ((len = is.read(b)) >0) {
                os.write(b, 0, len);
            }
            // 告诉客户端
            os2.write("上传成功".getBytes());
            os2.flush();
        }catch (Exception e) {
            e.printStackTrace();
        }
    }
}
